package com.example.cloud.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RequestMapping("/payment")
@RestController
@Slf4j
public class PaymentController {

    @Value("${server.port}")
    private int port;

    @Autowired
    private Environment env;

    @GetMapping("/{orderId}")
    public ResponseEntity<String> payment(@PathVariable("orderId") String orderId) {
        return ResponseEntity.ok("Success payment orderId: " + orderId + ", port: " + port);
    }


    @GetMapping("/config")
    public ResponseEntity<String> config() {
        String property = env.getProperty("configserver.uname");
        log.info("config: {}", property);
        return ResponseEntity.ok(property);
    }
}
